package com.gitee.ywj1352.jdk8;


/**
 * @author wenjie.yang
 * @date 2/21/2020 2:18 PM
 */
public class StreamTimeDemo {

    public static int i  = 0;

    //交替打印
    public static void main(String[] args) {
        Object lock = new Object();
        Runnable run = ()->{
            while (true){
                synchronized (lock){
                    lock.notify();
                    System.out.println(Thread.currentThread().getId() +":"+ i++);
                    try {
                        Thread.sleep(500);
                        lock.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }

        };
        Thread t1 = new Thread(run);
        Thread t2 = new Thread(run);
        t1.start();
        t2.start();
    }

}
